<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/admin_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--semantic-ui的cdn引入-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
</head>
<body>

    <!--导航部分-->
    <nav th:replace="admin/admin_fragments ::menu" class="ui inverted attached segment">
        <div class="container">
            <div class="ui inverted stackable menu">
                
                <h2 class="ui teal header item m-padding-up-dowm-min">后台管理</h2>

                <a href="" class="item"><i class="home icon"></i>博客</a>

                <a href="" class="item"><i class="edit icon"></i>分类</a>

                <a href="" class="item"><i class="tags icon"></i>标签</a>

                <!--头像栏-->
                <div class="right menu">
                    <div class="ui dropdown item">
                        <div class="text">
                            <i class="user icon"></i>
                            lgb
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="#" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </nav>
    <!--二级导航-->
    <div th:replace="admin/admin_fragments ::secondary_menu(1)" class="ui attached pointing menu">
        <div class="container">
            <a href="#" class="item">发布</a>
            <a href="#" class="active item">列表</a>
        </div>
    </div>


    <!--中间内容-->
    <div class="m-footer-padding-up-dowm-min">
        <div class="ui container">

            <!--搜索表单-->
            <div class="ui segment form">
                <!--意义不明，用于帮助下方的上一页，下一页-->
                <input type="hidden" name="page">
                <div class="ui inline fields">
                    <!--文章标题-->
                    <div class="ui field">
                        <input type="text" name="title" placeholder="文章标题" id="blog_title">
                    </div>

                    <!--文章类型-->
                    <div class="ui field">
                        <div class="ui labeled action input">
                            <div class="ui type selection dropdown">
                                <input type="hidden" name="typeId">
                                <i class="dropdown icon"></i>
                                <div class="default text">文章分类</div>
                                <div class="menu">
                                    <!--data-value才是传递到后端的值-->
                                    <div class="item" th:each="type : ${types}" th:data-value = "${type.id}" th:text="${type.name}">错误日志</div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!--是否推荐-->
                    <div class="ui field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="recommend" name="recommend">
                            <label for="recommend">推荐文章</label>
                        </div>
                    </div>

                    <div class="ui field">
                        <!--清空按钮-->
                        <button id="clear-btn" class="clear ui orange basic button mini">
                            清空
                        </button>
                        <!--搜索按钮-->
                        <button class="ui teal basic button mini" type="button" id="search_btn">
                            <i class="search icon"></i>
                            搜索
                        </button>
                    </div>
                </div>
            </div>

            <div id="table-container">
                <!--表格-->
                <table class="ui celled table" th:fragment="blogList">

                    <!--表头-->
                    <thead>
                    <tr>
                        <th></th>
                        <th>标题</th>
                        <th>类型</th>
                        <th>推荐</th>
                        <th>状态</th>
                        <th>跟新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>

                    <!--表体-->
                    <tbody>
                    <tr th:each="blog , iterStat : ${page.content}">
                        <td th:text="${iterStat.count}">1</td>
                        <td th:text="${blog.title}">标题</td>
                        <td th:text="${blog.type.name}">种类</td>
                        <td th:text="${blog.recommend} ? '是' : '否'">？</td>
                        <td th:text="${blog.published} ? '发布' : '未发布'"></td>
                        <td th:text="${blog.updateTime}">跟新时间</td>
                        <td>
                            <a class="ui mini teal basic button" th:href="@{/admin/blog_manage/{id}/update(id = ${blog.id})}">编辑</a>
                            <a class="ui mini red basic button" th:href="@{/admin/blog_manage/{id}/delete(id = ${blog.id})}">删除</a>
                        </td>
                    </tr>
                    </tbody>

                    <!--两个按钮-->
                    <tfoot>
                    <tr>
                        <th colspan="6">
                            <div class="ui right floated pagination menu" th:if="${page.totalPages} > 1">
                                <button onclick="page(this)" th:attr="data-page = ${page.number} - 1" class="item" th:unless="${page.first}">上一页</button>
                                <button onclick="page(this)" th:attr="data-page = ${page.number} + 1" class="item" th:unless="${page.last}">下一页</button>
                            </div>

                            <a class="ui blue basic button" th:href="@{/admin/blog_manage/input}">新增</a>
                        </th>
                    </tr>
                    </tfoot>

                </table>
                <!--消息提示-->
                <div class="ui success message" th:unless="${#strings.isEmpty(message)}" th:text="${message}">新增成功</div>
            </div>

        </div>
    </div>

    <!--底部footer-->
    <footer th:replace="admin/admin_fragments ::footer" class="ui inverted center aligned vertical segment m-footer-padding-up-dowm-min">
        <div class="container">
            <!--grid:横向分成16份,底下的元素为3+3+3+7-->
            <div class="ui divided  inverted grid">

                <div class="three wide column">
                    <h4 class="ui inverted header">二维码</h4>
                    <img src="..\..\static\images\二维码.png"  style="width: 80px;">
                </div>

                <div class="three wide column">
                    <h4 class="ui inverted header">个人博客</h4>
                    <div class="ui inverted list link">
                        <a href="#" class="item">1.0 xxx</a>
                        <a href="#" class="item">2.0 xxx</a>
                        <a href="#" class="item">3.0 xxx</a>
                    </div>
                </div>

                <div class="three wide column">
                    <h4 class="ui inverted header">联系我</h4>
                    <div class="ui inverted list link">
                        <a href="#" class="item">微信:13776710591</a>
                        <a href="#" class="item">QQ:2899847639</a>
                        <a href="#" class="item">GitHub:xxxxxxx</a>
                    </div>
                </div>

                <div class="seven wide column">
                    <h4 class="ui inverted header">个人博客</h4>
                    <p>
                        emmm,你要说点什么
                    </p>
                </div>
            </div>

            <!--一条线-->
            <div class="ui inverted section divider"></div>
            <p>emmm,你要说点什么</p>

        </div>
    </footer>

    <!--引入jquery和semantic-ui-->
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
    <script>
        //下拉的使用
        $('.ui.dropdown').dropdown({
            on:'hover'
        })

        function page(obj){
            $("[name = 'page']").val($(obj).data("page"));
            loaddata();
        }

        //ajax发送请求
        function loaddata() {
            $("#table-container").load(/*[[@{/admin/blog_manage/search}]]*/"/admin/blog_manage/search",{
                title : $("[name='title']").val(),
                typeId : $("[name='typeId']").val(),
                recommend : $("[name='recommend']").prop('checked'),
                page : $("[name='page']").val()
            });
            console.log("success")
        }

        //点击按钮发送请求
        $('#search_btn').click(function (){
            loaddata();
        })

        //清空按钮
        $('#clear-btn').on(
            'click',function (){
                //分类选择设置为空
                $('.ui.type.dropdown')
                    .dropdown('clear');
                //标题输入设置为空
                $('#blog_title').val('');
                //是否推荐设置为空
                // 取消Checkbox的选中状态
                $('#recommend').prop('checked', false);
            }
        )
    </script>
</body>

<style>
    /*semantic-ui注释覆盖需要加important*/

    /*用于调整导航上下边距*/
    .m-padding-up-dowm-min{
        padding-top: 0.2em !important;
        padding-bottom: 0.2em !important;
    }

    /*用于调整footer的上下边距*/
    .m-footer-padding-up-dowm-min{
        padding-top: 5em !important;
        padding-bottom: 5em !important;
    }

    /*在一行内显示*/
    .m-inline-block{
        display: inline-block !important;
    }
</style>
</html>